package com.stylefeng.guns.modular.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.modular.purchase.service.IPurchaseService;
import com.stylefeng.guns.modular.system.model.PurchaseGoods;
import com.stylefeng.guns.modular.system.dao.PurchaseGoodsMapper;
import com.stylefeng.guns.modular.purchase.service.IPurchaseGoodsService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author LiuXin
 * @since 2018-09-12
 */
@Service
public class PurchaseGoodsServiceImpl extends ServiceImpl<PurchaseGoodsMapper, PurchaseGoods> implements IPurchaseGoodsService {

    @Autowired
    private IPurchaseService purchaseService;

    @Override
    public boolean deleteGoodsAndListRecord(Long purchaseId) {
        EntityWrapper<PurchaseGoods> entityWrapper = new EntityWrapper<>();
        entityWrapper.eq("purchase_id", Long.valueOf(purchaseId));
        boolean success = this.delete(entityWrapper);
        boolean deletePurchase = purchaseService.deleteById(Long.valueOf(purchaseId));
        return  success && deletePurchase;
    }
}
